<template>
  <div>
    <h1>人员列表</h1>
    <h3 style="color: red">Count组件求和为：{{ sum }}</h3>
    <h3>列表中第一个人的名字是：{{ firstPersonName }}</h3>
    <input type="text" placeholder="请输入名字！" v-model="name" />
    <button @click="add(name)">添加</button>
    <button @click="addWang(name)">添加一个姓王的人</button>
    <button @click="addServer">添加一个服务器交互</button>
    <ul>
      <li v-for="p in personList" :key="p.id">{{ p.name }}</li>
    </ul>
  </div>
</template>

<script>
import { mapGetters, mapMutations, mapState, mapActions } from "vuex";
export default {
  name: "Person",
  data() {
    return {
      name: "",
    };
  },
  computed: {
    ...mapState("personOptions", ["personList"]),
    ...mapState("countOptions", ["sum"]),
    ...mapGetters("personOptions", ["firstPersonName"]),
  },
  methods: {
    ...mapMutations("personOptions", { add: "ADD_PERSON" }),
    ...mapActions("personOptions", {
      addWang: "addPersonWang",
      addServer: "addServer",
    }),
  },
};
</script>